package com.bjpowernode.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.bjpowernode.DlykServerApplication;
import com.bjpowernode.constant.DicEnum;
import com.bjpowernode.entity.TProduct;
import org.apache.commons.math3.stat.descriptive.summary.Product;

import java.util.List;

public class IntentionProductConverter implements Converter<Integer> {
    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        //获取excel中的值
        String excelValue = cellData.getStringValue();

        //从缓存中找到产品数据
        List<TProduct> productList = (List<TProduct>)DlykServerApplication.cacheMap.get(DicEnum.INTENTION_PRODUCT.getCode());

        for (TProduct tProduct : productList) {
            if (tProduct.getName().equals(excelValue)) {
                return tProduct.getId();
            }
        }

        return productList.get(0).getId();
    }
}
